package network.Demo04;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @Author Miku
 * @Create 2021/5/8 16:09
 */
public class UdpServerDemo {
    public static void main(String[] args) throws Exception {
        //开放端口
        DatagramSocket socket = new DatagramSocket(9999);
        //接收数据包
        byte[] buffer = new byte[1024];
        DatagramPacket packet = new DatagramPacket(buffer, 0, buffer.length);

        //阻塞接受
        socket.receive(packet);
        System.out.println(new String(packet.getData(),0,packet.getLength()));
        //关闭连接
        socket.close();
    }
}
